package org.jeecg.modules.wangyue.controller.sys;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.base.controller.JeecgController;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.wangyue.constant.DelFlagConstant;
import org.jeecg.modules.wangyue.constant.IsLiveConstant;
import org.jeecg.modules.wangyue.entity.ServiceItems;
import org.jeecg.modules.wangyue.entity.ServiceType;
import org.jeecg.modules.wangyue.model.req.ReqCommonModel;
import org.jeecg.modules.wangyue.model.res.ResUserRoleInfoModel;
import org.jeecg.modules.wangyue.service.IServiceItemsService;
import org.jeecg.modules.wangyue.service.IServiceItemsServiceTypeService;
import org.jeecg.modules.wangyue.service.IServiceJsService;
import org.jeecg.modules.wangyue.service.IServiceTypeService;
import org.jeecg.modules.wangyue.utils.CommonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
* @Description: 服务类型管理
* @Author: jeecg-boot
* @Date:   2023-06-30
* @Version: V1.0
*/
@Slf4j
@Api(tags="服务类型管理")
@RestController
@RequestMapping("/wangyue/sys/serviceType")
public class ServiceTypeManageController extends JeecgController<ServiceType, IServiceTypeService> {
   @Autowired
   private IServiceTypeService serviceTypeService;


    /**
     * 服务类型管理-分页列表查询
     * @param pageNo
     * @param pageSize
     * @return
     */
    @AutoLog(value = "服务类型管理-分页列表查询")
    @ApiOperation(value="服务类型管理-分页列表查询", notes="服务类型管理-分页列表查询")
    @GetMapping(value = "/list")
    public Result<?> queryPageList(@RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
                                   @RequestParam(name="pageSize", defaultValue="10") Integer pageSize) {
        QueryWrapper<ServiceType> queryWrapper = new QueryWrapper<>();
        queryWrapper.orderByAsc("sort").orderByDesc("create_time");
        Page<ServiceType> page = new Page<ServiceType>(pageNo, pageSize);
        IPage<ServiceType> pageList = serviceTypeService.page(page, queryWrapper);
        return Result.OK(pageList);
    }



    /**
     * 服务类型管理-开关显示
     *
     * @param serviceType
     * @return
     */
    @AutoLog(value = "服务类型管理-开关显示")
    @ApiOperation(value="服务类型管理-开关显示", notes="服务类型管理-开关显示")
    @PostMapping(value = "/switchShow")
    public Result<?> switchShow(@RequestBody ServiceType serviceType) {
        if(serviceTypeService.switchShow(serviceType)){
            return Result.OK("服务类型开关操作成功！");
        }
        return Result.error("服务类型开关操作失败！");
    }


    /**
     * 服务类型管理-添加或修改
     *
     * @param serviceType
     * @return
     */
    @AutoLog(value = "服务类型管理-添加或修改")
    @ApiOperation(value="服务类型管理-添加或修改", notes="服务类型管理-添加或修改")
    @PostMapping(value = "/addOrEdit")
    public Result<?> addOrEdit(@RequestBody ServiceType serviceType) {
        if(oConvertUtils.isEmpty(serviceType.getId())){ //如果是新增
            serviceType.setServiceTypeCode(CommonUtil.getOrderNum()); //随机生产一个唯一code
        }

        if(serviceTypeService.saveOrUpdate(serviceType)){
            return Result.OK("添加或修改成功！");
        }
        return Result.error("添加或修改失败！");
    }


    /**
     * 服务类型管理-通过id删除
     *
     * @param reqCommonModel
     * @return
     */
    @AutoLog(value = "服务类型管理-通过id删除")
    @ApiOperation(value="服务类型管理-通过id删除", notes="服务类型管理-通过id删除")
    @DeleteMapping(value = "/delete")
    public Result<?> delete(@Valid @RequestBody ReqCommonModel reqCommonModel) {
        if(serviceTypeService.deleteServiceType(reqCommonModel)){
            return Result.OK("删除操作成功！");
        }
        return Result.error("删除操作失败！");
    }



}
